package com.fanben100.biz;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import com.fanben100.constant.SystemConstant;
import com.fanben100.domain.LoginModel;
import com.fanben100.domain.Operater;
import com.fanben100.gui.TerminalFrame;

/**
 * 已登录状态
 * 
 * @author Administrator
 * 
 */
public class LogonState extends RegistState {

	@Override
	public void handle(JFrame frame) {
		super.handle(frame);
		// 开始控制权限,限制特定功能不可使用,此处只禁用了商家注册菜单
		LoginModel currentOperater = ((TerminalFrame) frame)
				.getConnectOperater();
		if (currentOperater != null
				&& currentOperater instanceof ValidLoginModel) {
			LoginModel loginModel = ((ValidLoginModel) currentOperater)
					.getLoginModel();
			boolean isOperaterLogin = (loginModel != null && loginModel instanceof Operater);
			// Operater operater = (Operater)currentOperater;
			int menuCount = frame.getJMenuBar().getMenuCount();
			for (int i = 0; i < menuCount; i++) {
				JMenu menu = frame.getJMenuBar().getMenu(i);
				menu.setEnabled(true);
				// menu.setEnabled(false);
				int menuItemCount = menu.getItemCount();
				for (int j = 0; j < menuItemCount; j++) {
					JMenuItem item = menu.getItem(j);
					if (item == null) {
						continue;
					}
					if (SystemConstant.REGIST_MENU_TEXT.equals(item.getText())) {
						if (isOperaterLogin) {
							item.setEnabled(false);
						} else {
							item.setEnabled(true);
						}
					} else {
						item.setEnabled(true);
					}
				}
			}
		}
	}
}
